#!/usr/bin/python

"""
Pour utiliser ce script, il faut installer "SciPy"

 => http://www.scipy.org/Installing_SciPy
    
"""

import scitools.easyviz as ev
import numpy as np

class Plot(object):
    
    def __init__(self):
        self.setXAxis()
        self.functs = []
                    
    def prepare(self, (a, b, c)):
        if b == 0:
            raise ValueError('b can not be equal to 0.')
        else:
            self.functs.append((a,b,c))
    
    def setXAxis(self, xmin = -10, xmax = 10):
        self.xmin = xmin
        self.xmax = xmax        
    
    def reset(self):
        self.setXAxis()
        self.functs = []
        
    def draw(self):
        ev.title('Exercices sur les droites')    
        ev.xlabel('x')
        ev.ylabel('y')
        ev.hold('off')
        for a,b,c in self.functs:
            t = np.linspace(self.xmin, self.xmax, 200)
            y = (-a*1.0/b) * t + (c*1.0/b)
            ev.plot(t, y, grid = True, legend = '%.3f*x + %.3f*y = %.3f' % (a, b, c))
            ev.hold('on')            


        
        
if __name__ == '__main__':
    p = Plot()
    p.prepare((1,1,3))
    p.prepare((-2,1,-1))
    p.draw()
    raw_input()
